<template>
	<div class="myContent">
        <!--头部 标题为  item.inspectTitle-->
		<!--<div style="height:2rem;"></div>-->
		<div class="centent" style="flex:1;overflow-y:auto;-webkit-overflow-scrolling: touch;">
			<!--商品列表-->
			<div class="aui-content" >
				<ul class="aui-list aui-media-list commodity_list subtotal_list">
					<li class="aui-list-item baoguo-list-item baoguo-root" style="padding-right: 0.75rem;">
						<div  class="title">
							<div>
								<span>检测人：{{dataList.inspectMan}}</span>
							</div>
							<div >
								<span>检测时间：{{getTime(dataList.inspectTm)}}</span>
								<span class="jieguo">检测结果：{{dataList.inspectResult}}</span>
							</div>
						</div>
					</li>
					<li class="aui-list-item baoguo-list-item baoguo-root noBorder" style="padding-right: 0.75rem;">
						<div  class="title" v-html="dataList.inspectDetail">
							
						</div>
						
					</li>
				</ul>
			</div>
			<!--商品列表 end-->
		</div>
	</div>

</template>

<script>

import {mapGetters,mapMutations} from "vuex";
import axios from 'axios';
import getUrl from '../../utils/getUrlSearch.js';
import { CHANGE_NAVIGATION } from '../../config/postMessage-types';
	export default {
	  	name: 'hello',
	  	data () {
	    	return {
				dataList:{}
			}
		},
		computed: {
			
		},
		components: {

	    },
	    methods: {
            setHead(title){
                let titleConfig = JSON.stringify({
                    type: CHANGE_NAVIGATION,
                    params: {
                        title: title
                    }
                })
                setTimeout(() => {
                    window.postMessage(titleConfig)
                },0)
            },
	    	initDate(){
                let search = getUrl();
                let sessionId = search.sessionId;
                let rid = search.rid;
                let params = {};
                params.storeCode = search.storeCode;
                params.inspectionDate = search.inspectionDate;
                this.getData(params,sessionId,rid);
            },
            getData(params,sessionId,rid) {
                let url = global.api.base_host + "/inspectionReport";
                let config = {
                    url: url,
                    method: "GET",
                    params,
                    headers:{ "sessionId":sessionId }
                }
                axios(config).then((res) => {
                    console.log(res,'食品');
                    if(res.data.returnCode == 1) {
                        var arr = res.data.data[0].results;
                        var compare = function (prop) {
                            return function (obj1, obj2) {
                                var val1 = obj1[prop];
                                var val2 = obj2[prop];
                                if (val1 < val2) {
                                    return -1;
                                } else if (val1 > val2) {
                                    return 1;
                                } else {
                                    return 0;
                                }
                            }
                        }
                        let contentDate = arr.sort(compare("inspectTm")).reverse();
                        contentDate.map((item,index) => {
                            if(item.rid == rid){
                                this.setHead(item.inspectTitle)
                                this.dataList = item;
                            }
                        })
                    }
                }).catch((err) => {
                    console.log(err,'食品检测接口报错');
                })
            },
	    	//转换时间格式
			getTime(param){
				if(param){
				  	  let date = new Date(param);
					  let year = date.getFullYear();
					  let month = checkTime(date.getMonth() + 1);
					  let day = checkTime(date.getDate());
					  let hour = checkTime(date.getHours());
					  let min = checkTime(date.getMinutes());
					  let sec = checkTime(date.getSeconds());
					function checkTime(i) {
					    if (i < 10) {
					      i = '0' + i;
					    }
					    return i;
					  }
	
					  return month+ ' ' + '-' + ' ' + day + ' ' + hour + ' ' + ":" + ' ' + min;
			    }else{
			   	  return '';
			    }
			}
	    },
		created () {
            
			this.initDate();
		},
		mounted () {
			// initDomTree(this.getDomTree[this.page]);
		},
		updated() {
			//页面更新完毕
			// initDomTree(this.getDomTree[this.page]);
		}
	}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
	.aui-searchbar, .aui-bar-nav {
		position: static;
	    left: 0;
	    top: 0;
	    z-index: 12;
	}

	.title{
		text-align: left;
		padding-top: 1rem;
		padding-bottom: 0.5rem;
		min-height: 3rem;
	}
	.title span{
		font-size: 0.8rem;
	}
	.jieguo{
		/* margin-left: 0.5rem; */
	}
	.baoguo-root{
		border-bottom: 1px solid #eaeaea;
	}
	.noBorder{
		border-bottom:0;
	}
	.myContent{
		width: 100%;
	    height: 100%;
	    display: flex;
	    flex-direction: column;
	    justify-content: space-between;
	}
</style>